* Economic Footprints: Mapping Coin Circulation and Economic Networks in Ancient Rome

* Change working directory
cd "/results"


********************************************************************************
* Table S1. Determinants of Local Money Demand

* Load data
clear all
use /data/Table_S1_Data.dta, clear

* MODEL 1: Poisson
* https://stats.oarc.ucla.edu/stata/dae/poisson-regression/
poisson raio_60km d_civic d_military d_economic d_religious port_5km
poisson, irr
outreg2 using Table_S1.txt, nolabel ctitle(Poisson) drop(i.id_country) addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), number_iterations, e(ic)) dec(4)
outreg2 using Table_S1_EFORM.txt, nolabel ctitle(Poisson) drop(i.id_country) dec(4) eform


* MODEL 2: Zero-inflated Poisson regression
* https://stats.oarc.ucla.edu/stata/dae/zero-inflated-poisson-regression
zip raio_60km d_civic d_military d_economic d_religious port_5km,  inflate(_cons) forcevuong
zip, irr
outreg2 using Table_S1.txt, nolabel ctitle(ZIP) drop(i.id_country) addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), number_iterations, e(ic)) dec(4)
outreg2 using Table_S1_EFORM.txt, nolabel ctitle(ZIP) drop(i.id_country) dec(4) eform


* MODEL 3: Negative binomial regression
* https://stats.oarc.ucla.edu/stata/dae/negative-binomial-regression/
nbreg raio_60km d_civic d_military d_economic d_religious port_5km
nbreg, irr
outreg2 using Table_S1.txt, nolabel ctitle(NBREG) drop(i.id_country) addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), number_iterations, e(ic)) dec(4)
outreg2 using Table_S1_EFORM.txt, nolabel ctitle(NBREG) drop(i.id_country) dec(4) eform


* MODEL 4: Zero-inflated negative binomial regression
* https://stats.oarc.ucla.edu/stata/dae/zero-inflated-negative-binomial-regression/
zinb raio_60km d_civic d_military d_economic d_religious port_5km, inflate(_cons) forcevuong zip
zinb, irr
outreg2 using Table_S1.txt, nolabel ctitle(ZINB) drop(i.id_country) addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), number_iterations, e(ic)) dec(4)
outreg2 using Table_S1_EFORM.txt, nolabel ctitle(ZINB) drop(i.id_country) dec(4) eform


********************************************************************************

* Load data
clear all
use /data/Table_S2_S4_data.dta, clear

* Table S2. Probit Regression Model
* Figure S1. Adjusted Predictions of the Neighboring Findspot

local RAIO "10 25 50 100 150 200 250 300"
foreach RAIO_2 of local RAIO {

probit dummy_number_records log_orbis_distance i.dummy_w_records`RAIO_2'km
* summ log_orbis_distance
margins dummy_w_records`RAIO_2'km, at(log_orbis_distance =(0(0.5)4))

marginsplot, name(mygraph, replace) noci scheme(s1mono) legend(order(1 "Neighboring findspots (`RAIO_2' km)=0" 2 "Neighboring findspots (`RAIO_2' km)=1") size(small) symxsize(10)) ytitle("Pr(dummy=1): Predicted probability of" "coin presence at the findspot–mint pair", margin(r=2)) xtitle("Log distance (ORBIS)", margin(t=2)) title("") ylabel(0(0.1)0.8)

graph display mygraph

outreg2 using Table_S2.txt, nolabel ctitle(`RAIO_2') addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), pseudo-R-squared, e(r2_p), number_iterations, e(ic)) dec(4)
* graph export Fig_S1_Probit_`RAIO_2'km.png, replace
graph export "Fig_S1_Probit_`RAIO_2'km.pdf", as(pdf) replace	
}


* Table S4. Spatial Interaction Model: Zero-Inflated Negative Binomial Regression over Time
foreach year of num 1/15 {

preserve
gen P`year' = log_orbis_distance

egen size_mint_records_`year'= sum(records_`year'), by(mint_id)
egen size_find_records_`year' = sum(records_`year'), by(findspot_id)

rename size_mint_records_`year' size_mint
rename size_find_records_`year' size_find
rename dummy_w_records_`year'_10km dummy_w_records_year_10km

zinb records_`year' P`year' size_mint size_find port_10km, inflate (dummy_w_records_year_10km) 

estimates store T`year'
estimates save "/results/T`year'", replace
 
restore

outreg2 using Table_S4_.txt, nolabel ctitle(`year') addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), number_iterations, e(ic)) dec(4)
}

* Clear all
clear all

* Check and install coefplot if needed
cap which coefplot
if _rc {
    ssc install coefplot, replace
}

* Open the models
foreach year of num 1/15 {
    estimates use "/results/T`year'"
    estimates store T`year'
}

coefplot T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15, vertical drop(_cons size_mint size_find dummy_w_records_year_10km port_10km)  yline(0, lwidth(vthin) lpattern(dash)) ylabel(-0.8(0.1)0.1) l2title(Log (distance), size(small)) l1title(ORBIS: # days in the Summer, size(small)) b1title(Period (Year end), size(small)) xlabel(, labsize(small)) ylabel(, labsize(small)) ciopts(recast(rcap) lwidth(vthin) lcolor(gs6)) mcolor(black) pstyle(p1) legend(off) coeflabels(P1="235-136 BCE" P2="225-126 BCE" P3="215-116 BCE" P4="205-106 BCE" P5="195-96 BCE" P6="185-86 BCE" P7="175-76 BCE" P8="165-66 BCE" P9="155-56 BCE" P10="145-46 BCE" P11="135-36 BCE" P12="125-26 BCE" P13="115-16 BCE" P14="105-6 BCE"	P15="95 BCE to 4 CE", angle(vertical)) graphregion(color(white) lstyle(none))

graph export "Figure_5.pdf", as(pdf) replace	
* graph export "Figure_5.png", replace

* Clear temporary file
foreach year of num 1/15 {
    capture erase "/results/T`year'.ster"
}


********************************************************************************
* Table S3

* Load data
clear all
use /data/Table_S3_DATA_CHRR_ORBIS, clear

* Criate variables
local RAIO "10 20 30 40 50 60 70 80 90 100"
foreach RAIO_2 of local RAIO {
egen size_mint_`RAIO_2'km= sum(records_`RAIO_2'km), by(orbis_origin)
la var size_mint_`RAIO_2'km "Size of mint i"

egen size_findspot_`RAIO_2'km = sum(records_`RAIO_2'km), by(orbis_destination)
la var size_findspot_`RAIO_2'km "Size of findspot j"
}


* Spatial Interaction Model: Zero-Inflated Negative Binomial Regression
* Dependent variables: Number of coin records in the findspot-mint pair
local RAIO "10 20 30 40 50 60 70 80 90 100"
foreach RAIO_2 of local RAIO {

preserve

drop if size_mint_`RAIO_2'km == 0
drop if size_findspot_`RAIO_2'km == 0

rename size_mint_`RAIO_2'km size_mint
rename size_findspot_`RAIO_2'km size_findspot
rename port_5km ancient_port_5km

zinb records_`RAIO_2'km log_orbis_distance size_mint size_findspot ancient_port_5km, inflate(_cons)
restore

outreg2 using Table_S3.txt, nolabel ctitle(`RAIO_2') addstat(chi-squared, e(chi2), p-value_chi, e(p), log_likelihood, e(ll), number_iterations, e(ic)) dec(4)
outreg2 using Table_S3_EFORM.txt, nolabel ctitle(`RAIO_2') dec(4) eform
}

